package com.yypx.common.intercetor;

import java.util.Map;
import java.util.ResourceBundle;

import javax.servlet.http.HttpServletRequest;

import org.apache.commons.lang.StringUtils;
import org.apache.log4j.Logger;
import org.apache.struts2.ServletActionContext;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Controller;

import com.yypx.common.utils.StringUtil;
import com.opensymphony.xwork2.Action;
import com.opensymphony.xwork2.ActionContext;
import com.opensymphony.xwork2.ActionInvocation;
import com.opensymphony.xwork2.interceptor.AbstractInterceptor;

public class LoginInterceptor extends AbstractInterceptor
	{
		/*private final static Logger logger=Logger.getLogger(LoginInterceptor.class);
		private static final String RESOURCENAME = "verification";
		private static final String CHECKENABLE="checkother.enabled"; 
		private static final String CHECKFORM = "check-form";
		private static final ResourceBundle res = ResourceBundle.getBundle(RESOURCENAME);*/  
	@Override
	public String intercept(ActionInvocation invocation) throws Exception
	{
		    ActionContext actionContext = invocation.getInvocationContext();   
			Map session = actionContext.getSession();
			//通过session 判断用户是否登录
			if(session!=null&&session.get("userid")!=null)
			{
				    return invocation.invoke();
			}
			//setToGoingURL(session, invocation);
			return Action.LOGIN;
	}
	
	private void setToGoingURL(Map session,ActionInvocation invocation)
	{
	    
		String url="";
		HttpServletRequest req = (HttpServletRequest) invocation.getInvocationContext().get(ServletActionContext.HTTP_REQUEST);
		if ("GET".equals(req.getMethod()))
		{
			url = req.getRequestURI();
			if (StringUtil.isStringHasContent(req.getQueryString()))
			{
				url = url + "?" + req.getQueryString();
			}
			//session.put(Constants.GOTO_URL_KEY, url);
		}
	}
}

